package com.peace.hospital.mapper.drugstorage;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peace.hospital.entity.drugstorage.Waentry;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;


/**
 * <p>
 * 入库单表 Mapper 接口
 * </p>
 *
 * @author xie
 * @since 2019-11-12
 */
@Mapper
public interface WaentryMapper extends BaseMapper<Waentry> {
//    插入入库表的信息
    @Insert("insert into drugstorage.waentry(staid,waedbsource,waedate) values(#{staid},#{waedbsource},date_format(now(),'%y-%m-%d'))")
    public int addWaentry(Waentry waentry);

//    查询入库表最后一条入库id
    @Select("select waeid\n" +
            "from drugstorage.waentry\n" +
            "ORDER BY waeid DESC\n" +
            "limit 1")
    public int findLastId();
// 根据id 查询入库单信息
    @Select("select waeid,staid,waedate from drugstorage.waentry where waeid=#{waeid}")
    @Results({
            @Result(column="staid",property="staffinfo", one=@One(select="com.peace.hospital.mapper.publicn.StaffinfoMapper.findById", fetchType= FetchType.LAZY))
    })
    public Waentry findById(int waeid);

//根据员工编号和入库日期查询入库单编号
    @Select("select waeid,waedate,staid from drugstorage.waentry where staid=#{staid} and waedate=#{waedate}")
    @Results({
            @Result(column="staid",property="staffinfo", one=@One(select="com.peace.hospital.mapper.publicn.StaffinfoMapper.findById", fetchType= FetchType.LAZY))
    })
    public List<Waentry> findByWaedAndStaId(Waentry waentry);
}
